package com.cn.kabalifeuser.ui.my.fragment;

import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.base.LazyFragment;
import com.cn.kabalifeuser.config.LoginHelper;
import com.cn.kabalifeuser.ui.integral.adapter.ShoppingMallAdapter;
import com.cn.kabalifeuser.ui.integral.bean.ShoppingMalListBean;
import com.cn.kabalifeuser.ui.my.activity.VipPresenter;
import com.cn.kabalifeuser.ui.my.activity.VipView;
import com.cn.kabalifeuser.ui.my.adapter.VipRightsAndInterestsAdapter;
import com.cn.kabalifeuser.ui.my.bean.VipInfoBean;
import com.cn.kabalifeuser.utils.RxToast;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 晓林 on 2020/9/25.
 * function: 权益
 */
public class VipRightsAndInterestsFragments extends LazyFragment<VipView, VipPresenter> implements VipView {

    @BindView(R.id.tv_data)
    RecyclerView tvData;


    List<VipInfoBean.ResultBean> mList;
    VipRightsAndInterestsAdapter mAdapter;

    private int mId;

    public static VipRightsAndInterestsFragments getInstance(int mid) {
        VipRightsAndInterestsFragments fragment = new VipRightsAndInterestsFragments();
        fragment.mId = mid;
        return fragment;
    }

    @Override
    protected VipPresenter createPresenter() {
        return new VipPresenter();
    }

    @Override
    protected void onUserVisible() {

    }

    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_vip_info;
    }

    @Override
    public void onReLoggedIn(String msg) {
        RxToast.error(msg);
        LoginHelper.againGoToLoginActivity(getMe());
    }

    @Override
    public void onError(String msg) {
        RxToast.error(msg);
    }

    @Override
    public Context _getContext() {
        return null;
    }

    @Override
    public void onShoppingMalListSuccess(ShoppingMalListBean bean) {

    }

    @Override
    public void onVipInfoSuccess(VipInfoBean bean) {
        mAdapter.replaceData(bean.getResult());
    }

    @Override
    public void initView(View view) {
        super.initView(view);
        ButterKnife.bind(this, view);
        mList = new ArrayList<>();
        LinearLayoutManager layoutManager3 = new LinearLayoutManager(getMe());
        layoutManager3.setOrientation(LinearLayoutManager.VERTICAL);
        layoutManager3.setSmoothScrollbarEnabled(true);
        layoutManager3.setAutoMeasureEnabled(true);
        tvData.setLayoutManager(layoutManager3);
        tvData.setNestedScrollingEnabled(false);
        //创建适配器
        mAdapter = new VipRightsAndInterestsAdapter(R.layout.fragment_vip_info_item, mList);
        //给RecyclerView设置适配器
        tvData.setAdapter(mAdapter);
        mPresenter.onVipInfoData(LoginHelper.getLonginData().getResult());
    }
}
